package com.gopay.common.cps.manager.gsrt.impl;

import com.gopay.common.cps.dao.gsrt.GsrtAccountDrawDao;
import com.gopay.common.cps.manager.gsrt.GsrtAccountDrawQueryManager;
import com.gopay.common.domain.gsrt.GsrtAccountDraw;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 
 * G商融通提现Manager实现
 * @author zyt
 * @2016年4月19日 @上午11:25:15
 *
 */
@Service("gsrtAccountDrawQueryManager")
public class GsrtAccountDrawQueryManagerImpl implements GsrtAccountDrawQueryManager {

	@Resource(name = "gsrtAccountDrawDao")
	private GsrtAccountDrawDao gsrtAccountDrawDao;
	
	 private final String FIND_TIMEOUT_ORDER_BY_TIMESPAN_SQL = "SELECT  c.id  FROM GSRT_ACCOUNT_DRAW C "
				+ "  where(C.TXN_STA_CD = '30001'"
				+ " AND ROUND(TO_NUMBER(SYSDATE - (C.CREATED_TS+0))*24*60) >= :timeSpan) ";
	    

	@Override
	public List<GsrtAccountDraw> getByGopayOrderId(String gopayOrderId) {
		String hql=" from GsrtAccountDraw where gopayOrderId=:gopayOrderId ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("gopayOrderId", gopayOrderId);
		List<GsrtAccountDraw> list=gsrtAccountDrawDao.findByHql(hql, param);
		return list;
	}

	@Override
	public List<GsrtAccountDraw> getByMerIdAndMerOrderId(String merId, String merOrderId) {
		String hql=" from GsrtAccountDraw where merCustId=:merCustId and  merOrderId=:merOrderId";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("merCustId", merId);
		param.put("merOrderId", merOrderId);
		List<GsrtAccountDraw> list=gsrtAccountDrawDao.findByHql(hql, param);
		return list;
	}

	@Override
	public List<Object> findTimeoutListByTimeSpan(int timeSpan) {
		Map m = new HashMap();
		m.put("timeSpan", timeSpan);
		List<?> result = gsrtAccountDrawDao.findBySql(FIND_TIMEOUT_ORDER_BY_TIMESPAN_SQL, m);
		return (List<Object>) result;
	}

	@Override
	public GsrtAccountDraw findByTransDtlSq(Long transDtlSq) {
		String hql=" from GsrtAccountDraw where transDtlSq=:transDtlSq ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("transDtlSq", transDtlSq);
		List<GsrtAccountDraw> list=gsrtAccountDrawDao.findByHql(hql, param);
		if(list.size() > 0){
			return list.get(0);
		}
		return null;
	}
}
